﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using COMOSOFT.Class;
using System.Net.Mail;

namespace COMOSOFT.Main.Froms
{
    public partial class FrmFogotPass : Form
    {
        ClassShare cls = new ClassShare("FrmFogotPass");
        public FrmFogotPass()
        {
            InitializeComponent();
        }

        private void bnt_Ok_Click(object sender, EventArgs e)
        {
           try
           {
               if (txt_Account.Text != "" && txt_Account.Text != null)
               {
                   DataTable dtb = cls.GetData("sp_ForgotPassWord", new string[] { "@Staffno" }, new object[] { txt_Account.Text });
                   if (dtb.Rows.Count > 0)
                   {
                       MailMessage message = new MailMessage();
                       SmtpClient Client = new SmtpClient();
                       Client.Host = "smtp.gmail.com";
                       Client.Port = 587;
                       Client.Credentials = new System.Net.NetworkCredential("dinhdongcntt@gmail.com", "Dong_OuIt@2711");
                       Client.EnableSsl = true;
                       Client.DeliveryMethod = SmtpDeliveryMethod.Network;
                       message.From = new MailAddress("dinhdongcntt@gmail.com");
                       message.Sender = new MailAddress("dinhdongcntt@gmail.com");
                       message.To.Add(new MailAddress(dtb.Rows[0]["Email"].ToString()));
                       message.Subject = "Forgot Password";
                       message.Body = "COMOSOFT Systems is pleased to announce to Email: " + dtb.Rows[0]["Email"].ToString() +
                                     " </br> Your is Password: " + dtb.Rows[0]["Password"].ToString() + "</br></br></br> ";
                       message.IsBodyHtml = true;
                       Client.Send(message);
                       MessageBox.Show("COMOSOFT Systems sent your password to email " + dtb.Rows[0]["Email"].ToString(), "Send email...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                       this.Close();
                   }
                   else
                       MessageBox.Show("Staff No is Wrong!");
               }
               else
                   MessageBox.Show("Staff No is Empty!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.Close();
            }           
        }
    }
}
